package band.wukong.practice.mq.activemq.hello;

import band.wukong.practice.mq.activemq.hello.topic.TopicSubscriber;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.jms.*;

/**
 * @author wukong(wukonggg@139.com)
 */
public class HelloMessageListener implements MessageListener {

    private static final Logger logger = LoggerFactory.getLogger(HelloMessageListener.class);

    private String comsumerName;
    private Session session;

    public HelloMessageListener(String consumerName, Session session) {
        this.comsumerName = consumerName;
        this.session = session;
    }

    @Override
    public void onMessage(Message msg) {
        try {
            TextMessage message = (TextMessage) msg;
            logger.debug("消费者" + comsumerName + "收到消息: " + message.getText());
            session.commit();
        } catch (JMSException e) {
            e.printStackTrace();
        }
    }
}
